use image::{DynamicImage, GenericImageView, ImageBuffer, Rgba};

#[flutter_rust_bridge::frb(sync)]
pub fn luma_image(src: &str, dist: &str) {
    let img = image::open(src).expect("Failed to open image");
    let (width, height) = img.dimensions();
    let mut gray_image = ImageBuffer::new(width, height);

    for (x, y, pixel) in img.pixels() {
        let Rgba([r, g, b, _]) = pixel;
        let luma = (0.299 * r as f32 + 0.587 * g as f32 + 0.114 * b as f32) as u8;
        gray_image.put_pixel(x, y, image::Luma([luma]));
    }
    gray_image.save(dist).expect("Failed to save image");
}
